package org.example.supplychain.mapper;

import org.apache.ibatis.annotations.*;
import org.example.supplychain.domain.User;

import java.util.List;

@Mapper
public interface UserMapper {
    @Insert("INSERT INTO user(user_name,password,nickname,phone,role,createDate) VALUES (#{userName},#{password},#{nickname},#{phone},#{role},#{createDate})")
    void addUser(User user);

    @Delete("DELETE FROM user WHERE user_name = #{userName}")
    void deleteUserByUserName(String userName);

    @Update("UPDATE user SET password = #{password},nickname=#{nickname},phone = #{phone},role = #{role} WHERE  user_name= #{userName}")
    void updateUser(User user);

    @Update("UPDATE user SET password = #{password} WHERE user_name = #{userName}")
    void updatePassword(User user);

    @Update("UPDATE user SET nickname = #{nickname} WHERE user_name = #{userName}")
    void updateNickname(User user);

    @Update("UPDATE user SET phone = #{phone} WHERE user_name = #{userName}")
    void updatePhone(User user);

    @Update("UPDATE user SET role = #{role} WHERE user_name = #{userName}")
    void updateRole(User user);

    @Select("select * from user where user_name = #{userName}")
    User getUserByUserName(String userName);

    @Select("select * from user")
    List<User> getAllUsers();
}
